package com.creawor.hz_market.servlet;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import report.ReportService;

public class reportServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public reportServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		OutputStream out1=null;
		try{
			response.setHeader("Pragma","No-cache"); 
			response.setHeader("Cache-Control","no-cache"); 
			response.setDateHeader("Expires", -10);
			response.setCharacterEncoding("GBK");
			response.reset();
			response.setContentType("application/vnd.ms-excel;");
			
			
		    //response.addHeader("Content-Disposition","attachment;filename=reportServlet.xls");
			response.setHeader("Accept-ranges", "bytes");
			//String []names=request.getParameterNames();
			Enumeration enu= request.getParameterNames();
			String chinnel=request.getParameter("channels");
			String group=request.getParameter("groups");
			String company=request.getParameter("balance_offices");
			String customers=request.getParameter("customers");
			String adres=request.getParameter("adres");
			String kehu=request.getParameter("kehures");
			String channelres=request.getParameter("qdaores");
			String communityres=request.getParameter("shequres");
			String businessres=request.getParameter("yewures");
			
			String employeeres=request.getParameter("yuangongres");
			
			String netres=request.getParameter("netjichures");
			String groupjieru=request.getParameter("groupjieru");
			String netbusinessres=request.getParameter("netyewures");
			String wuye=request.getParameter("wuye");
			String officeres=request.getParameter("bangongres");
			String cheliangres=request.getParameter("cheliang");
			String year=request.getParameter("year");
			String month=request.getParameter("month");
			
			ReportService report=new ReportService();
			out1=response.getOutputStream();

			report.buildReport(group,company,chinnel,customers,kehu,adres,channelres,communityres,businessres,employeeres,netres,groupjieru,netbusinessres,wuye,officeres,cheliangres,year,month,request,out1);
			
		}catch(Exception e){

		}finally{
			try{}catch(Exception e){out1.close();}}
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
